﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Mobile Index</title>
</head>
<body >
<input type="text" name="comment" value="" id="comment"><button onclick="sub()" >发送</button>
<!-- <table>

    <thead id="name">
    <tr>
        <th style="width: 300px;" id="comment1"></th>
    </tr>
    </thead>

</table> -->
</body>

<script src="/public/static/js/jquery.min.js"></script>
<script type="text/javascript">
    // 假设服务端ip为127.0.0.1
    // ws = new WebSocket("ws://"+document.domain+":8122");
    ws = new WebSocket("ws://39.108.162.84:8122");
    // ws = new WebSocket("ws://127.0.0.1:8122/?id=1");
    http://127.0.0.1:2346/?id=1
    // console.log(typeof(ws));
    ws.onopen = function() {
        // alert("连接成功");
        // // alert("给服务端发送一个字符串：tom");
        // ws.send('tom');
    };

    ws.onmessage = function(e) {
        // console.log(typeof(e.data));
        // $('#name').append("<tr><th style='width: 300px;'>"+e.data+"</th></tr>");
        alert("收到服务端的消息：" + e.data);
        // $("#comment1").append(e.data);
    };
    function sub(){
        var submit = $("#comment").val();
        // var data = '{"podcast_id":1, "mid":1, "type":"'+submit+'", "user_id":1, "username": "刷卡缴费", "appellation":"sssssbb", "user_picture": "skjfkjsdf", "is_speaker":0, "msg_content":{"content":"jfskaf", "url":"skfkjsjsfaaksf489344382"}, "msg_type":1,  "create_time":"1501462894"}';

        // var data = '{"podcast_id":2,"mid":"42462035987fa4ce2681" , "type":"'+submit+'", "is_speaker":1, "user_id":"1", "username":"colin", "appellation":"讲师", "user_picture":"https:www.com.jpg", "msg_content":{"content":"sjfhjs","url":"skjfksjfkasfjkfj.html"},"msg_type":"1"}';

        // var data = '{"type":"login","podcast_id":4,"user_picture":"jfhjfjsfjkaf","user_id":1}';
        var data = '{"type":"'+submit+'", "mid":"459acba00020fb","podcast_id":"4","username":"zbc","appellation":"sb","user_picture":"https://www.baidu.com/1.jpg","is_speaker":0,"msg_content":"啊啊啊消息", "msg_type":1, "temp":1233213, "user_id":1}';
        ws.send(data);
    }
</script>

</html>